package test.com.sms.selenium.singlepoint.util;

import org.openqa.selenium.By;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.remote.RemoteWebElement;

import test.com.sms.selenium.framework.SeleniumPageUtil;
import test.com.sms.selenium.util.SeleniumUtil;

public class SpHRSkillNewSubCategoryPageUtil extends SeleniumPageUtil {
	public final static By SMNSC_LINK_NEW_SUB_CATEGORY = By.xpath("//*[@id='3daa1c49-bee7-4336-bfbe-2a49d4d49be4']/a");
	public final static By SMNSC_SPAN_HEADER = By.id("ctl44_hdrSkillMaintenance_lblHeader");
	public final static By SMNSC_LINK_SAVE = By.xpath("//*[@id='0790172a-861a-45e1-a408-ef42dcc1dcb3']/a");
	public final static By SMNSC_LINK_CLOSE = By.xpath("//*[@id='3cf044f9-6c2e-4ab3-aeee-5af093c46053']/a");
	public final static By SMNSC_TD_CATEGORY = By.xpath("//*[@id='dvMaintItemEdit']/table[2]/tbody/tr[1]/td[1]");
	public final static By SMNSC_SELECT_CATEGORY = By.id("ctl44_cboCategory");
	public final static By SMNSC_TD_SUB_CATEGORY = By.xpath("//*[@id='trSubCategory']/td[1]");
	public final static By SMNSC_INPUT_SUB_CATEGORY = By.id("ctl44_txtSubCategory");
	
	public static void enterSkillMaintenanceNewSubCategoryPage(){
		SpHRSkillMaintenancePageUtil.enterHRSkillMaintenancePage();
		RemoteWebElement element = (RemoteWebElement)SeleniumUtil.getCachedElement(SpHRSkillMaintenancePageUtil.SMM_LINK_NEW);
		Actions action = new Actions(element.getWrappedDriver());
		action.moveToElement(element);
		SeleniumUtil.click(element);
		action.perform();
		SeleniumUtil.click(SeleniumUtil.findElement(SMNSC_LINK_NEW_SUB_CATEGORY));
		waitForPageToLoad();
	}
	
	public static void waitForPageToLoad() {
		SeleniumUtil.selectDefaultContent();
		SeleniumUtil.selectFrame(SpHomePageUtil.HOME_FRAME_CONTENT_NAME);
		SeleniumUtil.waitOnElements(new By[]{
				SMNSC_LINK_SAVE, SMNSC_LINK_CLOSE, SMNSC_SELECT_CATEGORY
			});
		SeleniumUtil.isDisplayed(SeleniumUtil.findElement(SMNSC_LINK_SAVE));
		SeleniumUtil.isDisplayed(SeleniumUtil.findElement(SMNSC_LINK_CLOSE));
		SeleniumUtil.isDisplayed(SeleniumUtil.findElement(SMNSC_SELECT_CATEGORY));
	}
}
